package
{
	import com.crlui.core.IResizeable;
	import com.crlui.core.state.SceneMachine;
	import com.crlui.manager.RenderManager;
	import com.crlui.manager.ResizeManager;
	
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;
	
	import milk.scene.SceneApp;
	
	[SWF(width=1000,height=600, backgroundColor=0,frameRate=30)]
	[Frame(factoryClass="milk.ui.Preloader")]
	public class MilkApp extends Sprite implements IResizeable
	{
		private var img:Loader;
		public function MilkApp()
		{
			this.addEventListener(Event.ADDED_TO_STAGE,stageHandler);
		}
		
		private function stageHandler(event:Event):void{
			this.removeEventListener(Event.ADDED_TO_STAGE,stageHandler);
			
			ResizeManager.instance.stage=stage;
			RenderManager.instance.stage=stage;
			
			img=new Loader();
			img.load(new URLRequest("assets/background.jpg"));
			img.contentLoaderInfo.addEventListener(Event.COMPLETE,update);
			this.addChildAt(img,0);
			
			var sce:SceneMachine=new SceneMachine(this);
			sce.add(new SceneApp());
			sce.state=SceneApp.NAME;
		}
		
		public function update(event:Event):void{
			
			img.contentLoaderInfo.removeEventListener(Event.COMPLETE,update);
			ResizeManager.instance.update(this);
		}
		
		public function resize(w:int, h:int):void
		{
			img.x=(w-img.width)>>1;
			img.y=(h-img.height)>>1;
			
		}
	}
}